﻿' Copyright © Microsoft Corporation.  All Rights Reserved.
' This code released under the terms of the 
' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
' <copyright file="SmoothSlider.vb" company="Microsoft">
'     Copyright © Microsoft Corporation. All rights reserved.
' </copyright>

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Input
Imports System.Windows.Media.Animation

Namespace ExpressionMediaPlayer
	Public Class SmoothSlider
		Inherits SensitiveSlider
		''' <summary>
		''' animation storyboard for smooth slider
		''' </summary>
		Private m_Animation As Storyboard
		Private m_DoubleAnimation As DoubleAnimation
		''' <summary>
		''' smooth animating slider
		''' </summary>
		Public Sub New()
			m_Animation = New Storyboard()
			m_DoubleAnimation = New DoubleAnimation()
			m_DoubleAnimation.Duration = New Duration(TimeSpan.FromSeconds(0.3))
			Storyboard.SetTarget(m_DoubleAnimation, Me)
			Storyboard.SetTargetProperty(m_DoubleAnimation, New PropertyPath("(SmoothSlider.Value)"))
			m_Animation.Children.Add(m_DoubleAnimation)
			Dim circleEasing As New CircleEase()
			circleEasing.EasingMode = EasingMode.EaseInOut
			m_DoubleAnimation.EasingFunction = circleEasing
		End Sub
		''' <summary>
		''' value of slider
		''' </summary>
		Public Shadows Property Value() As Double
			Set(ByVal value As Double)
				m_DoubleAnimation.From = MyBase.Value
				m_DoubleAnimation.To = value
				m_Animation.Begin()
			End Set
			Get
				Return MyBase.Value
			End Get
		End Property
		''' <summary>
		''' overriden to prevent updating the mediaelement position while the slider is animating.
		''' </summary>
		Public Overrides ReadOnly Property IsDragging() As Boolean
			Get
				If MyBase.IsDragging Then
					Return True
				End If

				Return m_Animation.GetCurrentState() = ClockState.Active
			End Get
		End Property
		''' <summary>
		''' update value on mouse click
		''' </summary>
		Protected Overrides Sub OnMouseClick(ByVal sender As Object, ByVal args As MouseButtonEventArgs)
			Value = CalcValue(args)
		End Sub
	End Class
End Namespace
